import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/login/Login'
import Home	from '@/components/home/Home'
import Users	from '@/components/users/Users'

Vue.use(Router)

const router = new Router({
  routes: [
    {
    	path:'/home',
    	component:Home,
    	children:[{path:'users',component:Users}]
    },
    {path: '/login',component: Login}
    
  ]
})
router.beforeEach((to, from, next) => {
//console.log("嘻嘻",to)
  if(to.path==="/login"){
  	//如果访问的是login页面直接放行 也就是任何人不管有没有登录都可以访问
  	next()
  } else{
  	const token =localStorage.getItem("token")
  	if(token){
  		next()
  	}else{
  		next('/login')
  	}
  	
  	
  }
  
})

export default router